package datacreation;

import guiobjects.Observation;
import java.util.ArrayList;

import commonfunctions.Matrix;


import user.data.Data;
import user.functions.WeightFunction;

/**
 * Creates the matrix of probabilities (really a two-dimensional array) 
 * from a list of Observations.
 * 
 * Really, "probability" is a misnomer; it hasn't been calculated formally, so "weight" would be a 
 * more accurate term, since it's a relatively arbitrary number that is assigned to an edge.
 * 
 * @author Trevor Terris
 *
 */

public class WeightsCreator 
{
	
	/**
	 * Creates the two-dimensional array, assuming that the list of observations has already been parsed.
	 * 
	 * @param observationList
	 * @param dirName
	 * @return
	 */
	public static Matrix createData(ArrayList<Observation> observationList, String dirName)
	{
        int size = observationList.size();
        Matrix toReturn = new Matrix(size);
        
        for (int i = 0; i < size - 1; i++)
        {
        	for (int j = i + 1; j < size; j++)
        	{
        		if (WeightFunction.shouldBeContradictory(observationList.get(i), observationList.get(j)))
        			toReturn.set(-1 * Data.DOMINANT_VALUE, i, j);
        		else if (!observationList.get(i).isEntranceNode && !observationList.get(j).isExitNode &&
        				!observationList.get(j).isEntranceNode && !observationList.get(i).isExitNode)
        			toReturn.set(WeightFunction.actualWeight(observationList.get(i), 
        					observationList.get(j)), i, j);
        		else if ((observationList.get(i).isEntranceNode || observationList.get(i).isExitNode)
        				&& observationList.get(i).dummyOf == j)
        			toReturn.set(WeightFunction.dummyWeight(observationList.get(i), 
        					observationList.get(j)), i, j);
        		else if ((observationList.get(j).isEntranceNode || observationList.get(j).isExitNode)
        				&& observationList.get(j).dummyOf == i)
        			toReturn.set(WeightFunction.dummyWeight(observationList.get(j), 
        					observationList.get(i)), i, j);
        		else if (observationList.get(i).isExitNode && observationList.get(j).isEntranceNode && observationList.get(i).camera == observationList.get(j).camera && observationList.get(i).frameNum == observationList.get(j).frameNum && Data.shouldConnectDummies)
        			toReturn.set(WeightFunction.actualWeight(observationList.get(i), observationList.get(j)), 
        					i, j);
        	}
        }
        return toReturn;
	}
}
